package com.mhc.suzuki.constant;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by HW
 * on 2017/8/22 15:28.
 */
public enum OrderStatusEnum {
  //征信结果待录入
  CREDITING(10, "征信结果待录入"),
  CREDIT_HAS_BEEN_RECORDER(11, "征信结果已录入"),
  UPDATE_CREDITING(12,"修改征信结果待录入"),
  UPDATE_HAS_BEEN_RECORDER(13, "修改征信结果已录入"),
  UNDER_REVIEW(21, "审核中"),
  APPLICATION_IS_APPROVED(22, "贷款申请通过"),
  APPLICATION_IN_NOT_APPROVED(23, "贷款审核未通过"),
  PAYMENT_REQUEST(31, "垫款审核中"),
  ALREADY_PAYMENT(32, "财务已垫款"),
  PAYMENT_REQUEST_REJECT(33, "垫款驳回"),
  CLOSED_ACCOUNT(41, "已结清"),
  CANCELLED(42, "已作废"),
  WITHDRAW(43, "已撤回"),
  BANK_YET_LENDING(51, "银行已放款");

  private Integer code;
  private String msg;

  OrderStatusEnum(Integer code, String msg) {
    this.msg = msg;
    this.code = code;
  }

  public String getMsg() {
    return this.msg;
  }

  public Integer getCode() {
    return this.code;
  }


  public static OrderStatusEnum getOrderStatusEnum(String msg) {
    for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) {
      if (orderStatusEnum.getMsg().equals(msg)) {
        return orderStatusEnum;
      }
    }
    //默认订单状态初始
    return OrderStatusEnum.CREDITING;
  }
  public static OrderStatusEnum getOrderStatusEnum(Integer code) {
    for (OrderStatusEnum orderStatusEnum : OrderStatusEnum.values()) {
      if (orderStatusEnum.code.equals(code)) {
        return orderStatusEnum;
      }
    }
    //默认订单状态初始
    return OrderStatusEnum.CREDITING;
  }

  /**
   * 判断订单状态是否处于银行放款之后
   * @param code
   * @return
   */
  public static Boolean isOrderStatusAfterBankLoan(Integer code) {
    //银行放款之后的状态列表
    List<OrderStatusEnum> afterBankLoanList = new ArrayList<>();
    afterBankLoanList.add(OrderStatusEnum.BANK_YET_LENDING);
    afterBankLoanList.add(OrderStatusEnum.CLOSED_ACCOUNT);
    for (OrderStatusEnum bakLoanEnum : afterBankLoanList) {
      if (code.equals(bakLoanEnum.getCode())) {
        return true;
      }
    }
    return false;
  }

}
